<!--  路由跳转 / tag 页面缓存 -->
<template>
    <div>
        <router-view #="{ Component }">
            <keep-alive v-if="shouldKeep()">
                <component :is="Component"/>
            </keep-alive>
            <component v-else :is="Component"/>
        </router-view>
    </div>
</template>

<script>
export default {
    methods: {
        shouldKeep() {
            let route = this.$route;
            // 获取 Vuex 中的 tagKeeps 数据
            const tagsKeep = this.$store.getters.tagsKeep;
            let isTagCache = tagsKeep.includes(route.path)
            // 判断当前组件是否需要被缓存
            // console.log("keepAlive: " + route.path + " --> " + isTagCache)
            return isTagCache;
        }
    }
};
</script>